#!/usr/bin/env python

import sys
import itertools

from kegg import get_server

def ChunkIter( iterable, chunk_size ):
    iterator = iter( iterable )
    while 1:
        chunk = list( itertools.islice( iterator, chunk_size ) )
        if not len( chunk ): break
        yield chunk


def main():
    server  = get_server()
    for chunk in ChunkIter(sys.stdin, 50):
        for res in server.btit(" ".join(l.strip() for l in chunk)).split('\n'):
            if res:
                kegg_id, info_str = res.split(' ', 1)
                info = [s.strip() for s in info_str.split(';')]
                if len(info) < 3:
                    definition = info[0]
                else:
                    definition = info[1]
                print "%s\t%s" % (kegg_id, definition)


if __name__ == '__main__':
    main()

